<template>
  <div>
    <div class="contbox6_10" v-if="type==0">
      <!-- 普通创建页 -->
      <p class="titlelist6_10"></p>
      <p class="titlelist6_10">
        结算信息
        <span style="color: #999;">&nbsp;&nbsp;/&nbsp;&nbsp;</span>
        添加银行卡
        
      </p>
      <el-form ref="form" :model="form" label-width="170px">
        <el-form-item label="银行卡(对公)" style="width: 100%;float: left;font-weight: bold;">
          <span></span>
        </el-form-item>
        <el-form-item label="公司名称" style="width: 100%;float: left;">
          <el-input
            v-model="form.companyName"
            style="width: 200px;margin-right: 40px;"
            placeholder="请输入公司名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="组织机构代码" style="width: 100%;float: left;">
          <el-input
            v-model="form.organizingCode"
            style="width: 200px;margin-right: 40px;"
            placeholder="请输入组织机构代码"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="企业证件号码" style="width: 100%;float: left;">
          <el-input
            v-model="form.enterNumber"
            style="width: 200px;margin-right: 40px;"
            placeholder="请输入企业证件号码"
          ></el-input>
        </el-form-item>-->
        <el-form-item label="开户行" style="width: 100%;float: left;">
          <el-select v-model="form.openBank" placeholder="请选择开户银行">
            <el-option
              :label="item.bankName"
              :value="item.bankCode"
              v-for="(item,index) in bankList"
              :key="index"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="企业对公账号" style="width: 100%;float: left;">
          <el-input
            v-model="form.corporateAccounts"
            style="width: 200px;margin-right: 40px;"
            placeholder="请输入企业对公账号"
          ></el-input>
        </el-form-item>
        <el-form-item label="企业预留经办人手机号码" style="width: 100%;float: left;">
          <el-input
            v-model="form.phoneNumber"
            style="width: 200px;margin-right: 40px;"
            placeholder="请输入企业预留经办人手机号码"
          ></el-input>
        </el-form-item>
        <el-form-item label="法人姓名" style="width: 100%;float: left;">
          <el-input
            v-model="form.personName"
            style="width: 200px;margin-right: 40px;"
            placeholder="请输入法人姓名"
          ></el-input>
        </el-form-item>
        <el-form-item label="法人证件号码" style="width: 100%;float: left;">
          <el-input
            v-model="form.corporateNum"
            style="width: 200px;margin-right: 40px;"
            placeholder="请输入法人证件号码"
          ></el-input>
        </el-form-item>
        <el-form-item label="企业电子邮箱" style="width: 100%;float: left;">
          <el-input
            v-model="form.officeName"
            style="width: 200px;margin-right: 40px;"
            placeholder="请输入企业电子邮箱"
          ></el-input>
        </el-form-item>
        <el-form-item style="width:100%;float: left; margin-top: 10px;text-align: left;">
          <el-button type="primary" @click="oemsnb()">提交</el-button>
          <el-button style="margin-right: 30px;" @click="shangyi()">返回</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { regionData, CodeToText, TextToCode } from "element-china-area-data";
export default {
  name: "route",
  data() {
    return {
      newType: "",
      huinbian: "",
      huixiantype: "",
      huiyuanzhazi: [],
      paizi: [],
      guishu: [],
      guishups: "",
      options: regionData,
      selectedOptions: [],
      type: 0,
      activeName: "first",
      tongdao: [],
      form: {
        companyName: "", //公司名称
        organizingCode: "", //组织机构代码
        enterNumber: "", //企业证件号码
        openBank: "", //开户行
        corporateAccounts: "", //企业对公账号
        phoneNumber: "", //企业经办人预留手机号
        personName: "", //法人姓名
        corporateNum: "", //法人证件号码
        officeName: "", //企业电子邮箱
      },
      bankList: [], //开户银行列表
      // urltype: this.GLOBAL.httpurl,
      uid: "",
    };
  },
  mounted: function () {
    window.scrollTo(0, 0);
    var _this = this;
    _this.openBankList();

    this.uid = _this.$route.params.uid; //获取 uid
    this.form.companyName = _this.$route.params.custName; //获取 企业名称
    this.form.organizingCode = _this.$route.params.organizCode; //获取 组织机构代码
    this.form.openBank = _this.$route.params.bankCode; //获取 开户行
    this.form.corporateAccounts = _this.$route.params.accountNo; //获取 企业对公账号
    this.form.phoneNumber = _this.$route.params.principalPhone; //获取 企业预留手机号
    this.form.personName = _this.$route.params.legalPersonName; //获取 法人姓名
    this.form.corporateNum = _this.$route.params.legalPersonIdCard; //获取 法人身份证号
    this.form.officeName = _this.$route.params.email; //获取 企业电子邮箱
    
  },
  components: {},

  methods: {
    //   返回到上级
    shangyi() {
      this.$router.go(-1);
    },
    //   form表达提交
    oemsnb() {
     let parme = {
        officeUid : this.uid, //获取 uid
        custName : this.form.companyName,  //获取 企业名称
        organizCode: this.form.organizingCode, //获取 组织机构代码
        bankCode : this.form.openBank,  //获取 开户行
        accountNo : this.form.corporateAccounts,  //获取 企业对公账号
        principalPhone : this.form.phoneNumber, //获取 企业预留手机号
        legalPersonName :this.form.personName,  //获取 法人姓名
        legalPersonIdCard : this.form.corporateNum,  //获取 法人身份证号
        email : this.form.officeName,  //获取 企业电子邮箱
        bankName : this.$route.params.bankName  //开户银行名称

      };
      const chinese = /^[\u4e00-\u9fa5]+$/; //中文
      const institutional = /[0-9A-HJ-NPQRTUWXY]{8}-[0-9A-HJ-NPQRTUWXY]/; //组织机构代码
      const enterpriseNum = /(^(?:(?![IOZSV])[\dA-Z]){2}\d{6}(?:(?![IOZSV])[\dA-Z]){10}$)|(^\d{15}$)/; //企业证件号码
      const accounts = /^[1-9]\d{7,29}$/; //企业对公账号
      const phone = /^1[3456789]\d{9}$/; //企业预留手机号
      const card = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; //身份证号
      const reg = /^bai([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/; //邮箱

      if (this.form.companyName == "") {
        this.$message({
          message: "公司名称不能为空",
          type: "warning",
        });
        return;
      }

      // if (!chinese.test(this.form.companyName)) {
      //   this.$message({
      //     message: "公司名称应为中文",
      //     type: "warning",
      //   });
      //   return;
      // }

      if (this.form.organizingCode == "") {
        this.$message({
          message: "请输入组织机构代码",
          type: "warning",
        });
        return;
      }

      // if (!institutional.test(this.form.organizingCode)) {
      //   this.$message({
      //     message: "请输入正确的组织机构代码",
      //     type: "warning",
      //   });
      //   return;
      // }


      //   if (!enterpriseNum.test(this.form.enterNumber)) {
      //     this.$message({
      //       message: "请输入正确的企业证件号码",
      //       type: "warning",
      //     });
      //     return;
      //   }

      if (this.form.openBank == "") {
        this.$message({
          message: "请选择开户行",
          type: "warning",
        });
        return;
      }

      if (this.form.corporateAccounts == "") {
        this.$message({
          message: "请输入企业对公账号",
          type: "warning",
        });
        return;
      }

      // if (!accounts.test(this.form.corporateAccounts)) {
      //   this.$message({
      //     message: "请输入正确的企业对公账号",
      //     type: "warning",
      //   });
      //   return;
      // }

      if (this.form.phoneNumber == "") {
        this.$message({
          message: "请输入企业预留经办人手机号码",
          type: "warning",
        });
        return;
      }

      if (!phone.test(this.form.phoneNumber)) {
        this.$message({
          message: "请输入正确的企业预留经办人手机号码",
          type: "warning",
        });
        return;
      }

      if (this.form.personName == "") {
        this.$message({
          message: "请输入法人姓名",
          type: "warning",
        });
        return;
      }

      //   if (!chinese.test(this.form.personName)) {
      //     this.$message({
      //       message: "请输入正确的法人姓名",
      //       type: "warning",
      //     });
      //     return;
      //   }

      if (this.form.corporateNum == "") {
        this.$message({
          message: "请输入法人证件号码",
          type: "warning",
        });
        return;
      }

      if (!card.test(this.form.corporateNum)) {
        this.$message({
          message: "请输入正确的法人证件号码",
          type: "warning",
        });
        return;
      }

      if (this.form.officeName == "") {
        this.$message({
          message: "请输入企业电子邮箱",
          type: "warning",
        });
        return;
      }

      // if (!reg.test(this.form.officeName)) {
      //   this.$message({
      //     message: "请输入正确的企业电子邮箱",
      //     type: "warning",
      //   });
      //   return;
      // }
      var _this = this;
      _this
        .axios({
          //axios请求
          method: "post",
          url:  "/api/office/enterpriseUserRegister",
          data: parme
        })
        .then(function (d) { 
          if (d.data.code == "0000") {
            window.open(d.data.data.retUrl); 
          } else {
            layer.open({
              content: d.data.msg,
              skin: "msg",
              time:  2, //1秒后自动关闭
            });
          }
          
        })
        .catch(function (error) {
          //axios请求失败回调
          console.log(error);
        });

      
    },

    // 开户银行
    openBankList() {
      var _this = this;
      _this
        .axios({
          //axios请求
          method: "post",
          url: "/bank/queryBank",
          data: {},
        })
        .then(function (d) {
          if (d.data.code == "0000") {
            _this.bankList = d.data.data;
            /*  _this.form.toOfficeUid = d.data.oemuid;*/
          } else {
            layer.open({
              content: d.data.msg,
              skin: "msg",
              time:  2, //1秒后自动关闭
            });
          }
        })
        .catch(function (error) {
          //axios请求失败回调
          console.log(error);
        });
    },
  },
};
</script>

<style scoped>
/* 单独样式 */
.contbox6_10 {
  width: 96%;
  margin-left: 2%;
  /*  height: 87.5vh; */
  overflow-x: auto;
  box-sizing: border-box;
  float: left;
}
.titlelist6_10 {
  width: 100%;
  float: left;
  font-size: 16px;
  color: #222;
  margin-top: 40px;
}
.sousuojg6_10 {
  float: left;
  font-size: 16px;
  color: #222;
  box-sizing: border-box;
  background-color: #f6f6f6;
  border-radius: 5px;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 256px;
  height: 160px;
  line-height: 160px;
  text-align: center;
}
.avatar {
  width: 256px;
  height: 160px;
  display: block;
  border-radius: 4px;
}
.cardNo {
  text-align: center;
  font-size: 14px;
}
</style>
